package com.liaoyifan.core.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import java.io.Serializable;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public interface CoreEnum<T extends Serializable> {

    @JsonValue
    T getValue();

    @SuppressWarnings("ResultOfMethodCallIgnored")
    static void unique(CoreEnum<?>[] values) {
        Arrays.stream(values)
                .collect(
                        Collectors.toMap(
                                CoreEnum::getValue,
                                Function.identity(),
                                (e1, e2) -> {
                                    throw new IllegalStateException(
                                            "REPEAT VALUE: " + e1.getValue());
                                }));
    }
}
